<template>
  <!-- 视频裁剪 -->
  <div>
    <el-dialog :visible.sync="dialogVisible" :show-close="false" width="800px" @close="close">
      <!-- <div class="header">
        <div><span class="line"></span>{{ detail.title }}</div>
        <i class="el-icon-close" @click="close"></i>
      </div>
      <div class="material-tag">
        <span class="tag" v-for="(item, index) in detail.labels">{{ item }}</span>
      </div>
      <div class="material-time">
        上传时间：{{ parseTime(detail.publishDatetime, '{y}-{m}-{d} {h}:{i}:{s}') }}
      </div> -->
      <div class="material-video">
        <!-- <vue-d-player ref="dplayer" :options="{ video: { url: detail.preViewUrl, pic: detail.coverUrl } }" :key="detail.id"
          @load="getVideoDuration"></vue-d-player> -->
          <video ref="dplayer" controls="" style="width: 100%;" name="media" class="frame-img" :key="detail.videoClipId" @loadedmetadata="getVideoDuration">
            <source :src="detail.previewUrl" type="video/mp4">
          </video>
      </div>
      <!-- 裁剪片段 -->
      <div>
        <el-slider v-model="detail.clip_time" range show-stops  :max="videoDuration">
        </el-slider>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="close">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "Preview",
  data() {
    return {
      title: "",
      dialogVisible: false,
      // 表单参数
      detail: {
        preViewUrl: ''
      },
      dp: null,
      options: {},
      dp: null, // DPlayer实例
      videoDuration: 0, // 视频时长
    };
  },
  mounted() { },
  methods: {
    getVideoDuration() {
      const videoElement = this.$refs.dplayer
      console.log(videoElement)
      const duration = videoElement.duration;
      console.log(duration,'时长')
      this.videoDuration = Math.floor(duration);
      // console.log(this.detail.clip_time,this.videoDuration,'ssssss1111111111111')
      // this.detail.clip_time =[0, this.videoDuration]
      // console.log(this.detail.clip_time,'sssss');
    },
    close() {
      this.dialogVisible = false;
    },
    result() {
      const videoElement = this.$refs.dplayer.dp
      

      // player.re
    },
    show(detail) {
      console.log(detail)
      this.detail = detail;
      this.dialogVisible = true;
      // this.getVideoDuration(detail.preViewUrl)
    },
    handleEdit() {

    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.detail);
      this.close()
      return
      this.$refs["model"].validate((valid, model) => {
        // if (valid) {
        // }
        console.log(valid, model);
      });
    },
  },
};
</script>
<style scoped lang="scss">
.btn {
  width: 100%;
  padding: 20px 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.material-video {
  img {
    width: 100%;
  }
}

.material-desc {
  max-height: 500px;
  overflow-y: scroll;
  line-height: 22px;
  font-size: 14px;
}

.header {
  display: flex;
  justify-content: space-between;
  padding: 20px 0 0;
  font-size: 18px;
  font-weight: 700;

  .line {
    display: inline-block;
    width: 2px;
    height: 13px;
    background-color: #2552E4;
    margin-right: 5px;
  }

  i {
    font-size: 26px;
    cursor: pointer;
    margin-left: 60px;
  }
}

.material-time {
  margin-bottom: 10px;
  border-bottom: 1px solid #D4DEEA;
  padding-bottom: 10px;
  font-size: 12px;
}

.material-tag {
  margin: 10px 0 10px;

  .tag {
    display: inline-block;
    background: rgba(9, 184, 68, 0.08);
    color: #09B844;
    padding: 3px 10px;
    font-size: 12px;
    border-radius: 2px;
    margin-right: 10px;
  }

  .tag:last-child {
    background: rgba(0, 87, 255, 0.08);
    color: #0057FF;
  }
}

::v-deep {
  .el-dialog__header {
    padding: 0;
  }
}
</style>
